<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
	<title>用户注册</title>
	<meta name="renderer" content="webkit">	
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">	
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">	
	<meta name="apple-mobile-web-app-capable" content="yes">	
	<meta name="format-detection" content="telephone=no">	
	<!-- load css -->
	<link rel="stylesheet" type="text/css" th:href="@{common/layui/css/layui.css}" href="common/layui/css/layui.css" media="all">
	<link rel="stylesheet" type="text/css" th:href="@{css/login.css}" href="css/login.css" media="all">
</head>
<body>
<div class="layui-canvs"></div>
<div class="layui-layout layui-layout-login">
	<h1>
		 <strong>在线刷题系统</strong>
		 <em>
			 On-line Question Brushing System
		 </em>
	</h1>
    <form th:id="registform" th:action="@{/user/register}" method="post" th:name="user">
        <div class="layui-user-icon larry-login">
            <input type="text" name="username" placeholder="用户名" class="login_txtbx"/>
        </div>
        <div class="layui-pwd-icon larry-login">
            <input type="password" name="password" placeholder="密码" class="login_txtbx"/>
        </div>
        <div class="layui-pwd-icon larry-login">
            <input type="password" name="password2" placeholder="确认密码" class="login_txtbx"/>
        </div>
        <div class="layui-pwd-icon larry-login">
            <input type="text" name="phone" placeholder="电话" class="login_txtbx"/>
        </div>
        <div class="layui-pwd-icon larry-login">
            <input type="text" name="email" placeholder="邮箱" class="login_txtbx"/>
        </div>

        <div class="layui-val-icon larry-login">
            <div class="layui-code-box">
                <input type="text" id="code" name="code" placeholder="验证码" maxlength="4" class="login_txtbx">

                <div style="float: right">
                    <button id="sendemail"  type="button" class="layui-btn" onsubmit="false" lay-submit="" lay-filter="demo1">点击获取验证码</button>
                </div>
            </div>
        </div>
        <!--    <div class="layui-val-icon larry-login">
                <div class="layui-code-box">
                    <input type="text" id="code" name="code" placeholder="验证码" maxlength="4" class="login_txtbx">
                    <img th:src="@{images/verifyimg.png}" src="images/verifyimg.png" alt="" class="verifyImg" id="verifyImg" onClick="javascript:this.src='xxx'+Math.random();">
                </div>
            </div>-->
        <div class="layui-submit larry-login">
            <input type="button" value="立即注册" class="submit_btn"/>
        </div>
    </form>

    <div class="layui-login-text">
		<p><a th:href="@{/login}" href="#" style="color: red;">已有账号，点此登陆</a>    <a th:href="@{/findmyuser}" href="#" style="color: #85C998;">忘记密码，点此找回</a></p>
    	<p>© 2019 薛国鹏 版权所有 联系方式(qq)：2043928998</p>
        <!--<p></p>-->
	</div>
</div>
<script type="text/javascript" th:src="@{/easyui/jquery-1.8.0.min.js}"></script>
<script type="text/javascript" th:src="@{common/layui/lay/dest/layui.all.js}" src="common/layui/lay/dest/layui.all.js"></script>
<script type="text/javascript" th:src="@{js/login.js}" src="js/login.js"></script>
<script type="text/javascript" th:src="@{jsplug/jparticle.jquery.js}" src="jsplug/jparticle.jquery.js"></script>

<link rel="stylesheet" type="text/css" th:href="@{/easyui/themes/default/easyui.css}">
<link rel="stylesheet" type="text/css" th:href="@{/easyui/themes/icon.css}">
<script type="text/javascript" th:src="@{/easyui/jquery.easyui.min.js}"></script>

<script type="text/javascript">
$(function(){
	$(".layui-canvs").jParticle({
		background: "#141414",
		color: "#E6E6E6"
	});
	//登录链接测试，使用时可删除
	$(".submit_btn").click(function(){
        var email = $(" input[ name='email' ] ").val().trim();
        var username = $(" input[ name='username' ] ").val().trim();
        var phone = $(" input[ name='phone' ] ").val().trim();

        var password = $(" input[ name='password' ] ").val().trim();
        var password2 = $(" input[ name='password2' ] ").val().trim();
        var code = $(" input[ name='code' ] ").val().trim();

        if(email.length == 0 || username.length == 0 || password.length == 0 || phone.length == 0 || password2.length == 0 || code.length == 0) {
            $.messager.alert("提示","登陆信息缺失","error");
        }else {
            if(password == password2) {
                //2，定义正则
                var reg_email = /^\w+@\w+\.\w+$/;
                //3，判断
                var flag_email = reg_email.test(email);

                var reg_phone = /^1[34578]\d{9}$/;

                var flag_phone = reg_phone.test(phone);
                if(flag_email == true && flag_phone == true) {

                    var targetUrl = $("#registform").attr("action");
                    var data = $("#registform").serialize();

                    $.ajax({
                        type:'post',
                        url:targetUrl,
                        cache: false,
                        data:data,  //重点必须为一个变量如：data
                        dataType:'text',
                        success:function(data){
                            if(data == "success") {
                                $.messager.alert("提示","注册成功，请登录","success");
                                window.location.href="/login";
                            }else {
                                $.messager.alert("提示",data,"error");
                            }
                        },
                        error:function(){
                            $.messager.alert("提示","请求失败","error");
                        }
                    })
                }else {
                    $.messager.alert("提示","邮箱或者手机号格式错误","error");
                }
            }else {
                $.messager.alert("提示","两次密码不一致","error");
            }
        }
	});


    $("#sendemail").click(function () {
        // alert("1111")
        var email = $(" input[ name='email' ] ").val().trim();
        // alert(email)
        //2，定义正则
        var reg_email = /^\w+@\w+\.\w+$/;
        //3，判断
        var flag_email = reg_email.test(email);
        if(email.length != 0 && flag_email == true) {
            $.messager.alert("提示","正在发送，请稍后","info");
            $.ajax({
                type:'post',
                url:"/mail/send"+"?email="+email,
                cache: false,
                data:email,  //重点必须为一个变量如：data
                dataType:'text',
                success:function(){
                    $.messager.alert("提示","发送成功","success")
                },
                error:function(){
                    $.messager.alert("提示","请求失败","error");
                }
            })
        }else {
            $.messager.alert("提示","邮箱格式错误","error");
        }
    });
});
</script>
</body>
</html>